import urllib.request
import urllib.parse
import json

# 百度翻译的API接口
url = "https://fanyi.baidu.com/sug"
word = input("请输入要查询的单词：")

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '
                  '(KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}

# 要加的参数
data = {
    'kw': word,
}

data = urllib.parse.urlencode(data).encode()

request = urllib.request.Request(url=url, headers=headers, data=data)

response = urllib.request.urlopen(request).read().decode('unicode_escape')

# 用Json模块把得到的json数据（其实它就是一种str字符串）转成Python中字典
response = json.loads(response)['data']

for word in response:
    print(word['k'] + '：' + word['v'])